package com.nuoniu.sibanyun.controller.cm;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.cm.CmContractStage;
import com.nuoniu.sibanyun.service.cm.ICmContractStageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 合同阶段 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/cm/contractStage")
@Api(tags = "合同阶段管理")
public class CmContractStageController extends BaseController {

    @Autowired
    private ICmContractStageService stageService;

    @ApiOperation("分页获取列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, CmContractStage contractStage) {
        return HttpResult.ok(stageService.pageList(page, contractStage));
    }

    @ApiOperation("保存")
    @PostMapping("saveStage")
    public HttpResult saveStage(@RequestBody CmContractStage contractStage) {
        if(StringUtils.isBlank(contractStage.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }

        if(StringUtils.isBlank(contractStage.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        stageService.saveStage(contractStage);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        stageService.removeById(id);
        return HttpResult.ok();
    }


}
